package com.aboverock.common.enums;


/**
 * 性别标识 枚举类型.
 *
 * @author Rock Wang
 */
public enum UserSexEnum {

    /** 未知(0). */
    UNKNOWN(0, "未知"),

    /** 男(1). */
    MALE(1, "男"),

    /** 女(2). */
    FEMALE(2, "女");

    private final Integer value;
    private final String description;

    UserSexEnum(Integer value, String description) {
        this.value = value;
        this.description = description;
    }

    /**
     * 获取值.
     *
     * @return value
     */
    public Integer getValue() {
        return value;
    }

    /**
     * 获取描述信息.
     *
     * @return description
     */
    public String getDescription() {
        return description;
    }

    /**
     * 根据值获取性别信息.
     *
     * @param value the value
     * @return the sex enum
     */
    public static UserSexEnum getSexEnum(Integer value) {
        if (null == value) {
            return UNKNOWN;
        }
        for (UserSexEnum sex : UserSexEnum.values()) {
            if (value.equals(sex.getValue())) {
                return sex;
            }
        }
        return UNKNOWN;
    }

    /**
     * 根据描述获取性别信息.
     *
     * @param description the description
     * @return the sex enum
     */
    public static UserSexEnum getSexEnum(String description) {
        if (null == description) {
            return UNKNOWN;
        }
        for (UserSexEnum sex : UserSexEnum.values()) {
            if (description.equals(sex.getDescription())) {
                return sex;
            }
        }
        return UNKNOWN;
    }

}